﻿using nanhua.BookStore.Entitys.OrderAggregate;
using nanhua.BookStore.Entitys.ProductCategoryAggregate;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Volo.Abp.Uow;

namespace nanhua.BookStore.Orders
{
    /// <summary>
    /// 产品类型领域种子数据初始化
    /// </summary>
    public class ProductCategoryDataSeedContributor : IDataSeedContributor, ITransientDependency
    {
        IProductCategoryRepository _productCategoryRepository;
        IGuidGenerator _guidGenerator;
        public ProductCategoryDataSeedContributor(IProductCategoryRepository productCategoryRepository, IGuidGenerator guidGenerator)
        {
            this._productCategoryRepository = productCategoryRepository;
            this._guidGenerator = guidGenerator;
        }
        [UnitOfWork]
        public async Task SeedAsync(DataSeedContext context)
        {
            if (await _productCategoryRepository.GetCountAsync() <= 0)
            {
                var productCategory = new ProductCategory(_guidGenerator.Create(),"PG_A001","手机类");
                await _productCategoryRepository.InsertAsync(productCategory);
            }
        }
    }
}
